/**
 * @Title: LoginResolver.java
 * @Package com.rongzhijia.jdq.back.api.interceptor
 * @author panzw@rongzhijia.com
 * @date 2017年5月9日 下午3:56:50
 * @version V1.0
 */
package com.zm.tools.util.spring;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
 * SpringMvc 参数注入
 */
public class ArgumentResolver implements HandlerMethodArgumentResolver {

	/* (non-Javadoc)
	 * @see org.springframework.web.method.support.HandlerMethodArgumentResolver#supportsParameter(org.springframework.core.MethodParameter)
	 */
	@Override
	public boolean supportsParameter(MethodParameter parameter) {
//		注入带有注解的相关参数
//		return parameter.getParameterAnnotation(TestContext.class) != null;
		return true;
	}

	/* (non-Javadoc)
	 * @see org.springframework.web.method.support.HandlerMethodArgumentResolver#resolveArgument(org.springframework.core.MethodParameter, org.springframework.web.method.support.ModelAndViewContainer, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.bind.support.WebDataBinderFactory)
	 */
	@Override
	public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
                                  NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
		try {
			return "test";
		} catch (Exception ex) {
			return null;
		}
	}

}
